<?php
namespace app\shop\controller;
use think\Db;
class Index extends Base{
    public function index(){
        $url=$this->request->domain();
    	$cates=Db::name('cates')->where('f_id',0)->where('state',1)->select();
        $banners=Db::name('banner')->where('state',1)->order('sort desc')->select();
        $products=Db::name('product')->where('state',1)->field('id,title,img')->order('id desc')->limit(0,4)->select();
        if($products){
            foreach ($products as $key => $value) {
                $products[$key]['price']=Db::name('spec_combination')->where('p_id',$products[$key]['id'])->where('state',1)->order('id asc')->value('money');
            }
        }
        if(!empty(input("param.latitude"))){
            $latitude=input("param.latitude");
        }else{
        	$latitude='30.57853';
        }
        if(!empty(input("param.longitude"))){
            $longitude=input("param.longitude");
        }else{
        	$longitude='114.2782';
        }
        $pagef=4*(1-1);
        $sql="select * from(select id,title,img,price,address,state,stars,ROUND(6378.138*2*ASIN(SQRT(POW(SIN(($latitude*PI()/180-`latitude`*PI()/180)/2),2)+COS($latitude*PI()/180)*COS(`latitude`*PI()/180)*POW(SIN(($longitude*PI()/180-`longitude`*PI()/180)/2),2)))*1000) AS distance from khdz_scenic_spot where state < 3 order by id desc) as a where a.distance<=5000000 limit ".$pagef.",4";
        $spots=Db::query($sql);
        $this->assign('cates',$cates);
        $this->assign('banners',$banners);
        $this->assign('products',$products);
        $this->assign('spots',$spots);
        $this->assign('url',$url);
        $this->assign('system',$this->system_set());
        return $this->fetch();
    }
}
